<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>跟随鼠标</title>
    <style>
        img {
            position: absolute;
        }
    </style>
</head>
<body>
    <img src="../元素操作/my.png" alt="">
    <script>
        var img = document.querySelector('img');
        document.addEventListener('mousemove',function(e) {
            //移动鼠标就会触发事假
            var x = e.pageX;
            var y = e.pageY;
            img.style.left = x - 100 + 'px'
            img.style.top = y - 110 + 'px'
        })
    </script>
</body>
</html> 